//
//  HWNavigationController.swift
//  HWPromoteProjectAPP
//
//  Created by 王昌健 on 2022/1/26.
//  Copyright © 2022 王昌健. All rights reserved.
//

import UIKit

class HWNavigationController: UINavigationController,UIGestureRecognizerDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        UINavigationBar.appearance().isTranslucent = false
        
        let textAttributes = [NSAttributedString.Key.font:UIFont.boldSystemFont(ofSize: 18),NSAttributedString.Key.foregroundColor:UIColor.colorWithHexString(hexString: "#333333")]
        UINavigationBar.appearance().titleTextAttributes = textAttributes
        
        UINavigationBar.appearance().tintColor = UIColor.colorWithHexString(hexString: "#333333")
        //        UINavigationBar.appearance().barTintColor = UIColor.white
        //        UINavigationBar.appearance().backIndicatorImage = UIImage()
        
        UINavigationBar.appearance().backIndicatorTransitionMaskImage = UIImage(named: "fanghui_QC")
        //        UINavigationBar.appearance().backIndicatorImage = UIImage(named: "navBack")
        UINavigationBar.appearance().shadowImage = UIImage()
        self.interactivePopGestureRecognizer?.isEnabled = true
        self.interactivePopGestureRecognizer?.delegate = self
        
        if #available(iOS 15, *){
            let appearance = UINavigationBarAppearance()
            appearance .configureWithOpaqueBackground()
            UINavigationBar.appearance().standardAppearance = appearance
            UINavigationBar.appearance().scrollEdgeAppearance = appearance
        }else{
            
        }

    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if (self.children.count > 0) {
            // 恢复滑动返回功能 -> 分析:把系统的返回按钮覆盖 -> 1.手势失效(1.手势被清空 2.可能手势代理做了一些事情,导致手势失效)
            viewController.hidesBottomBarWhenPushed = true;
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem.backItemWithimage(image: UIImage(named: "fanghui_QC") ?? UIImage(), highImage:  UIImage(named: "fanghui_QC") ?? UIImage(), target: self, action: #selector(self.back), title: " ")
            
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    @objc func  back() {
        self.popViewController(animated: false)
    }
}

extension HWNavigationController {
    
}
